<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('租户信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>租户编号：</label>
                                <input type="text" name="tenantCode"/>
                            </li>
                            <li>
                                <label>租户名称：</label>
                                <input type="text" name="tenantName"/>
                            </li>
                            <li>
                                <label>联系人：</label>
                                <input type="text" name="contactMan"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="contactNumber"/>
                            </li>
                            <li>
                                <label>支付状态：</label>
                                <select name="playStatus" th:with="type=${@dict.getType('sys_pay_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>实际到期时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginExpirationTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endExpirationTime]"/>
                            </li>
                            <li>
                                <label>租户类型：</label>
                                <select name="type" th:with="type=${@dict.getType('sys_tenant_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:tenant:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:tenant:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:tenant:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:tenant:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:tenant:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:tenant:remove')}]];
        var authFlag = [[${@permission.hasPermi('system:application:auth')}]];
        var playStatusDatas = [[${@dict.getType('sys_pay_status')}]];
        var typeDatas = [[${@dict.getType('sys_tenant_type')}]];
        var statusDatas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "system/tenant";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "租户信息",
                columns: [{
                    checkbox: true,
                    formatter:function(value, row, index){
                        // 根据row.列名   那状态确定返回 true/false
                        if (row.type=='0'){
                            return {
                                disabled : true
                            };
                        }
                    }
                },
                {
                    field: 'id',
                    title: 'uuid',
                    visible: false
                },
                {
                    field: 'tenantCode',
                    title: '租户编号'
                },
                {
                    field: 'tenantName',
                    title: '租户名称'
                },
                {
                    field: 'contactMan',
                    title: '联系人'
                },
                {
                    field: 'contactNumber',
                    title: '联系电话'
                },
                {
                    field: 'address',
                    title: '联系地址'
                },
                {
                    field: 'playStatus',
                    title: '支付状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(playStatusDatas, value);
                    }
                },
                {
                    field: 'expirationTime',
                    title: '实际到期时间'
                },
                {
                    field: 'type',
                    title: '租户类型',
                    formatter: function(value, row, index) {
                        if(value=='0'){
                            return '平台';
                        }
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注说明'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.type!='0'){
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + authFlag + '" href="javascript:void(0)" onclick="authApplication(\'' + row.tenantCode + '\')"><i class="fa fa-user"></i>分配子系统</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /* 租户管理-分配子系统 */
        function authApplication(tenantCode) {
            var url = prefix + '/authApplication/' + tenantCode;
            $.modal.open("分配子系统", url);
        }
    </script>
</body>
</html>